/**
 * Created by yang on 15/2/13.
 */
var later = require('later');

var child_process = require('child_process');
var sched = {
    schedules:[
        {h: [06], m: [0,0]}
    ]
};

var getMogInfo = require('./get_mongo_info');
var sendMail = require('./send_mail');
function autoBackup(){
    var pushReportStr = '';
    var child = child_process.spawn('sh',['/root/app/your_backup_project/auto.sh']);
    child.stdout.setEncoding('utf8');
    child.stdout.on('data', function(data) {
        pushReportStr += data;
        console.log(data);
    });
    child.stdout.on('close',function(data){
        getMogInfo(function(dbInfoJson){
            var dbInfoStr = JSON.stringify(dbInfoJson);
            sendMail('这里填写你需要通知的邮件或邮件组','数据自动备份报告',dbInfoStr + '\n' + '<br>' + pushReportStr);
        });
    });
}

//autoBackup();


later.setInterval(autoBackup,sched);

console.log('autoBackup will be exec at ' + JSON.stringify(sched.schedules));